import { useEffect } from 'react';
import { getLoadMapList, getTenantID, getSelectDataMapList } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
import { useDescriptionsType } from '@/components/DescriptionsType';
import { RegularExpression } from '@/common/constVariable';
import { Form, TreeSelect } from 'antd';
import TransferView from '../mview/TransferView';

const getUpdateConfig = ({ pageType }) => {
  /**  获取数据字典 */
  const { loadMapInfo, mapLoading } = getLoadMapList([
    `${getTenantID()}${ILoadMapTypeAll.MATERIAL_BRAND}`, //物料品牌
  ]);
  /** 物料品牌 */
  const assetBrand = getSelectDataMapList(loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_BRAND}`], 'name', 'id', true);
  /** 表单数据 */
  const [acceptForm] = Form.useForm();
  /** 切换表单 */
  useEffect(() => {
    if (pageType === 'view') {
      acceptForm.setFieldsValue({
        tableName: '实验室仓库',
        assetName: '电脑',
        sourceType: '采购',
        assetType: '仓库转移',
        assetValue: '100元',
        materialNum: '2',
      });
    } else if (pageType === 'Edit') {
      acceptForm.setFieldsValue({
        tableName: '实验室仓库',
        assetName: '电脑',
        sourceType: '采购',
        assetType: '仓库转移',
        assetValue: '100元',
        materialNum: '2',
      });
    }
  }, []);

  /** 表单配置 */
  const [config, methods] = useDescriptionsType({
    labelWidth: 190,
    basicForm: acceptForm,
    name: 'accept-addAndEdit',
    schemas: [
      {
        key: 'accept-basic',
        title: '基本信息',
        fieldChildren: [
          {
            field: `tableName`,
            label: `资产仓库`,
            component: 'InputTextArea',
            disabled: true,
            // initialValue: leftSelectName,
            required: true,
            placeholder: '请选择',
            autoSize: { minRows: 1, maxRows: 3 },
          },
          {
            field: `assetName`,
            label: `资产名称`,
            component: 'Input',
            disabled: pageType === 'view',
            placeholder: '请选择资产名称',
            required: true,
          },
          {
            field: `sourceType`,
            label: `资产来源`,
            component: 'Input',
            disabled: pageType === 'view',
            required: true,
            placeholder: '请输入资产来源',
          },
          {
            field: `assetType`,
            label: `资产类型`,
            component: 'Input',
            placeholder: '请选择',
            disabled: pageType === 'view',
            required: true,
            // options: assetType,
            // render: (text) => {
            //     return (
            //         <TreeSelect
            //             loading={mapLoading}
            //             disabled={pageType === 'view'}
            //             showArrow={pageType === 'view'}
            //             placeholder="请选择"
            //             // treeData={assetType}
            //             fieldNames={{
            //                 label: 'name',
            //                 value: 'value',
            //                 children: 'children',
            //             }}
            //             showSearch={true}
            //             treeNodeFilterProp={'name'}
            //             onSelect={(_value, node) => {
            //                 console.log('_value',_value);
            //                 acceptForm?.setFieldsValue({
            //                     materialType:_value,
            //                 });
            //             }}
            //         />
            //     )
            // },
          },
          {
            field: `assetValue`,
            label: `资产价值`,
            component: 'InputNumber',
            placeholder: '请输入',
            disabled: pageType === 'view',
            required: true,
            min: 1,
            patternMsg: '请输入整数',
          },
          {
            field: `materialNum`,
            label: `资产原数量`,
            required: true,
            component: 'InputNumber',
            disabled: pageType === 'view',
            placeholder: '请输入',
            min: 1,
            patternMsg: '请输入整数',
          },
          // {
          //     field: `shuomingwenjian`,
          //     label: `说明文件`,
          //     disabled: pageType === 'view',
          //     required: true,
          //     component: 'Input',
          //     placeholder: '请输入说明文件',
          // },
        ],
      },
      {
        key: 'accept-procurement',
        title: '资产信息',
        fieldCustomDom: <TransferView />,
      },
    ],
  });

  return {
    config,
    methods,
  };
};

export { getUpdateConfig };
